<template>
  <view class="contain">
    <view class="top-content"></view>
    <view class="top">
      <view v-for="(item, index) in data" :key="index" class="card">
        <view @click="enter(index)">
          <card :data="item" />
        </view>
      </view>
    </view>

    <!-- <view style="height: 60px"></view> -->

    <view class="footer">
      <u-button
        v-if="show"
        class="btn"
        @click="handleClick()"
        type="primary"
        :ripple="true"
        ripple-bg-color="#32afff"
      >一键完成</u-button>
      <u-button
        v-else
        class="btn"
        type="primary"
        :ripple="true"
        ripple-bg-color="#32afff"
        @click="handleTable()"
      >生成报告</u-button>
    </view>
  </view>
</template>

<script>
import card from '@/components/detail/crad.vue'
import {
  pointCheckDeviceDetail,
  pointCheckTaskDeviceAdd,
  pointCheckTaskDeviceEdit,
  pointCheckTaskDeviceRemove,
  pointCheckTaskDeviceQuickCreateReport
} from '@/api/index.js'
export default {
  components: {
    card
  },
  onLoad(val) {
    this.taskId = val.taskDeviceId
    this.Tdata = val.taskDeviceId
    this.id = val.Id
    this.timeone = val.timeone
    this.hour = val.hour
    this.minute = val.minute
    this.second = val.second
  },
  onShow() {
    this.show = true
    this.getList()
  },
  data() {
    return {
      show: true,
      taskId: '',
      id: '',
      length: 0,
      data: [
        {
          name: '波纹管',
          time: '2021-8-19 12:02',
          number: '01',
          position: '南京',
          normalNum: '',
          abnormalNum: '',
          needCheckNum: '',
          isCheck: false
        },
        {
          name: '承力承压件',
          time: '2021-8-19 12:02',
          number: '01',
          position: '南京',
          normalNum: '',
          abnormalNum: '',
          needCheckNum: '',
          isCheck: true,
          pointCheckDeviceDetails: []
        },
        {
          name: '附属件',
          time: '2021-8-19 12:02',
          number: '01',
          position: '南京',
          normalNum: '',
          abnormalNum: '',
          needCheckNum: '',
          isCheck: true,
          pointCheckDeviceDetails: []
        },
        {
          name: '工况',
          time: '2021-8-19 12:02',
          number: '01',
          position: '南京',
          normalNum: '',
          abnormalNum: '',
          needCheckNum: '',
          isCheck: true,
          pointCheckDeviceDetails: []
        }
      ]
    }
  },
  methods: {
    getList() {
      this.length = 0
      pointCheckDeviceDetail(this.Tdata).then(res => {
        this.data.forEach(item => {
          item.normalNum = res.data[item.name].normalNum
          item.abnormalNum = res.data[item.name].abnormalNum
          item.needCheckNum = res.data[item.name].needCheckNum
          item.pointCheckDeviceDetails =
            res.data[item.name].pointCheckDeviceDetails
          if (res.data[item.name].needCheckNum == '0') {
            this.length += 1
            if (this.length == 4) this.show = false
          }
        })
      })
    },
    enter(index) {
      switch (index) {
        case 0:
          uni.navigateTo({
            url:
              '/pages/detaildemo/detaildemo?id=' +
              this.id +
              '&taskId=' +
              this.taskId
          })
          break
        case 1:
          uni.navigateTo({
            url:
              '/pages/pressure/pressure?id=' +
              this.id +
              '&taskId=' +
              this.taskId
          })
          break
        case 2:
          uni.navigateTo({
            url: '/pages/along/along?id=' + this.id + '&taskId=' + this.taskId
          })
          break
        case 3:
          uni.navigateTo({
            url: '/pages/status/status?id=' + this.id + '&taskId=' + this.taskId
          })
          break
      }
    },
    handleClick() {
      const arr = []

      pointCheckDeviceDetail(this.Tdata).then(res => {
        res.data['工况'].pointCheckDeviceDetails.forEach(item => {
          arr.push(item.item)
        })
        if (arr.length == 0) {
          uni.showModal({
            title: '提示',
            content: '工况中温度、压力、运行周期为必填项！',
            success: res => {
              if (res.confirm) {
                // pointCheckTaskDeviceQuickCreateReport(this.Tdata).then(res => {
                //     this.getList()
                // })
                // this.show = false;
              } else if (res.cancel) {
              }
            }
          })
        } else {
          // console.log(arr)
          let tf=true
          arr.forEach(item1 => {
            if(arr.length == 4){
              tf=true
            }else if (item1 == '振动') {
              tf=false
            }else if(arr.length !=3){
              tf=false
            }
          })
           if(tf){
               uni.showModal({
             title: '提示',
             content: '确定将其他项全部标记为已完成？',
             success: res => {
               if (res.confirm) {
                 pointCheckTaskDeviceQuickCreateReport(this.Tdata).then(
                   res2 => {
                     this.getList()
                   }
                 )
                 this.show = false
               } else if (res.cancel) {
               }
             }
           })
           }else {
              uni.showModal({
                title: '提示',
                content: '工况中温度、压力、运行周期为必填项！',
                success: res => {
                  if (res.confirm) {
                    // pointCheckTaskDeviceQuickCreateReport(this.Tdata).then(res => {
                    //     this.getList()
                    // })
                    // this.show = false;
                  } else if (res.cancel) {
                  }
                }
              })
           }
        }
      })
    },
    handleTable() {
      uni.navigateTo({
        url:
          '/pages/vtable/vtable?id=' +
          this.Tdata +
          '&timeone=' +
          this.timeone +
          '&hour=' +
          this.hour +
          '&minute=' +
          this.minute +
          '&second=' +
          this.second
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.contain {
  height: 100%;
 
  position: relative;
  background-color: white;
}
.top-content {
  height: 160upx;
  background: linear-gradient(to left, #1040be, #026dff);
}
.top {
  height: calc(100% - 200rpx);
   overflow-y: auto;
  position: absolute;
  background-color: white;
  padding: 30rpx;
  width: 100%;
  top: 50rpx;
  border-radius: 40rpx 40rpx 0 0;
  .card {
    // background-color: white;
    border: 1px solid #eee;
    padding: 20rpx 20rpx;
    border-radius: 25rpx;
    box-shadow: 0 0 20rpx #eee;
    margin-bottom: 20rpx;
  }
}
.btn {
  width: 544rpx;
  height: 91rpx;
  background: linear-gradient(-34deg, #1040be, #026dff);
  border-radius: 46rpx;
  font-size: 36rpx;
  font-weight: 500;
  color: #ffffff;
}
</style>
